home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
art&graf.ix
/
art-0039
/
source
/
dcselimg.mod
< prev
next >
Wrap
Text File
|
1997-04-16
|
12KB
|
323 lines
IMPLEMENTATION MODULE DCSelImg;
(*---------------------------------------------------------------------*)
(* Select Rectangular portion of the picture. Update PicImage *)
(* Dialog with selected values. *)
(* *)
(* Assumptions: *)
(* 1) This routine does not have to rebuild the screen. *)
(* 2) The right mouse button pressed at any time will abort. *)
(* *)
(* The order of things happening is: *)
(* 1) Draw a rubber box of approximate size. *)
(* The box can be dragged and resized as follows: *)
(* If click and hold within box then *)
(* if within lower 1/3 pixels of bottom left corner then *)
(* resize box *)
(* else *)
(* drag the box *)
(* else *)
(* if left button then *)
(* update picture image *)
(* else *)
(* leave *)
(* endif *)
(* endif *)
(* *)
(* *)
(* Version 1.00 August 1988 L.G.Miller *)
(*---------------------------------------------------------------------*)
(* IMPORT Trace; *)
FROM DCGlobal IMPORT PictureImage,
HiRes, MedRes,
MedResMaxX, MedResMaxY,
HiResMaxX, HiResMaxY,
HiResScreen;
FROM DCScreen IMPORT DisplayFullPicture;
FROM ManyWindow IMPORT ShowMouse,
HideMouse,
VDIHandle;
IMPORT Graphics;
IMPORT Event;
FROM VDI IMPORT vswr_mode,
vsl_type,
vsl_color,
vsl_udsty,
vs_clip,
v_pline;
TYPE
PxyArrayType = ARRAY [ 0 .. 3 ] OF INTEGER;
RGBArrayType = ARRAY [ 0 .. 3 ] OF INTEGER;
CONST
CMinWidth = 20;
CMinHeight = 20;
CStartWidth = 200;
CStartHeight = 100;
CStretchRange = 10;
CVDIXorWriteMode = 3;
CLineType = 7; (* user line *)
FlatHand = 4;
PointHand = 3;
Arrow = 0;
PROCEDURE QueryOutsideBox ( mox, moy,
boxx, boxy, boxw, boxh : INTEGER ): BOOLEAN;
BEGIN
IF ( mox < boxx ) OR ( mox > ( boxx + boxw - 1 ) ) THEN
RETURN TRUE
END;
IF ( moy < boxy ) OR ( moy > ( boxy + boxh - 1 ) ) THEN
RETURN TRUE
END;
RETURN FALSE;
END QueryOutsideBox;
(*----------------------------------------------------------------------*)
(* If mouse in lower third of box then will select. *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryStretchBox( mox, moy,
boxx, boxy, boxw, boxh : INTEGER ) : BOOLEAN;
VAR w, h : INTEGER;
BEGIN
w := boxw DIV 3;
h := boxh DIV 3;
boxx := ( boxx + boxw - 1 ) - w;
boxy := ( boxy + boxh - 1 ) - h;
RETURN NOT QueryOutsideBox( mox, moy, boxx, boxy, w, h );
END QueryStretchBox;
PROCEDURE WaitMouseButton ( VAR mox, moy, mstate, kstate : CARDINAL );
CONST CMButtons = {14,15};
VAR dumc : CARDINAL;
BEGIN
mstate := 0;
REPEAT
dumc := Event.evnt_timer( LONGCARD(0) ); (* give other tasks chance to run *)
dumc := Graphics.graf_mkstate( mox, moy, mstate, kstate );
mstate := INTEGER( BITSET(mstate) * CMButtons );
(* do bitwise AND mask *)
UNTIL ( ( mstate # 0 ) & ( moy > 15 ) );
END WaitMouseButton;
PROCEDURE WaitNoMouseButton;
CONST CMButtons = {14,15};
VAR mox, moy, mstate, dummy : CARDINAL;
BEGIN
mstate := 0;
REPEAT
dummy := Event.evnt_timer( LONGCARD(0) ); (* give other tasks time to run *)
dummy := Graphics.graf_mkstate( mox, moy, mstate, dummy );
mstate := INTEGER( BITSET(mstate) * CMButtons );
(* do bitwise AND mask *)
UNTIL ( ( mstate = 0 ) & ( moy > 15 ) );
END WaitNoMouseButton;
PROCEDURE DrawXorBox( boxx, boxy, boxw, boxh : INTEGER );
VAR BoxCoords : ARRAY [ 0 .. 11 ] OF INTEGER;
BEGIN
HideMouse;
BoxCoords[0] := boxx;
BoxCoords[1] := boxy;
BoxCoords[2] := boxx + boxw - 1;
BoxCoords[3] := boxy;
v_pline( VDIHandle, 2, BoxCoords ); (* top horizontal *)
BoxCoords[0] := boxx + boxw - 1;
BoxCoords[1] := boxy+1;
BoxCoords[2] := BoxCoords[0];
BoxCoords[3] := boxy + boxh - 1;
v_pline( VDIHandle, 2, BoxCoords ); (* right vert *)
BoxCoords[0] := boxx;
BoxCoords[1] := boxy + boxh - 1 ;
BoxCoords[2] := boxx + boxw - 2 ;
BoxCoords[3] := BoxCoords[1];
v_pline( VDIHandle, 2, BoxCoords ); (* bottom horiz *)
BoxCoords[0] := boxx;
BoxCoords[1] := boxy + 1;
BoxCoords[2] := boxx ;
BoxCoords[3] := boxy + boxh - 2; (* left vert *)
v_pline( VDIHandle, 2, BoxCoords );
ShowMouse;
END DrawXorBox;
(*----------------------------------------------------------------------*)
(* Having problems with GrafRubberBox if start is too near top of *)
(* screen, so will start with a box in the middle of the screen. *)
(* I have no idea why it doesn't work properly yet. *)
(*----------------------------------------------------------------------*)
PROCEDURE DoMedResSelectImage ( VAR PictureImageDetails : PictureImage;
VAR Picture : HiResScreen );
CONST CRButton = 2;
CLButton = 1;
VAR mox, moy, mbutton, bkstate : CARDINAL;
boxx, boxy, boxw, boxh, mstate : CARDINAL;
dumi, i : INTEGER;
cliprect : PxyArrayType;
RGB : RGBArrayType;
BEGIN
dumi := vswr_mode( VDIHandle, CVDIXorWriteMode );
dumi := vsl_type( VDIHandle, CLineType );
vsl_udsty( VDIHandle, CARDINAL(0AAAAH) );
dumi := vsl_color( VDIHandle, 0 );
cliprect[0] := 0;
cliprect[1] := 0;
cliprect[2] := MedResMaxX;
cliprect[3] := MedResMaxY;
vs_clip( VDIHandle, TRUE, cliprect );
HideMouse;
DisplayFullPicture( Picture );
ShowMouse;
WaitNoMouseButton;
boxx := ( MedResMaxX DIV 2 ) - ( CStartWidth DIV 2 );
boxy := ( MedResMaxY DIV 2 ) - ( CStartHeight DIV 2 );
boxw := CStartWidth;
boxh := CStartHeight;
LOOP
DrawXorBox( boxx, boxy, boxw, boxh );
WaitMouseButton( mox, moy, mbutton, bkstate );
DrawXorBox( boxx, boxy, boxw, boxh );
IF ( mbutton = CRButton ) THEN
WaitNoMouseButton;
RETURN
END; (* right button = abort *)
(* outside box? ... accept rectangle if true *)
IF QueryOutsideBox( mox, moy, boxx, boxy, boxw, boxh ) THEN
EXIT
END; (* if *)
IF QueryStretchBox( mox, moy, boxx, boxy, boxw, boxh ) THEN
dumi := Graphics.graf_mouse(PointHand, NIL);
dumi := Graphics.graf_rubberbox( boxx, boxy, CMinWidth, CMinHeight,
boxw, boxh );
dumi := Graphics.graf_mouse(Arrow ,NIL);
ELSE
dumi := Graphics.graf_mouse(FlatHand, NIL);
dumi := Graphics.graf_dragbox( boxw, boxh, boxx, boxy,
0, 0, MedResMaxX+1, MedResMaxY+1,
boxx, boxy );
dumi := Graphics.graf_mouse(Arrow, NIL);
END; (* if *)
END; (* loop *)
(* convert med res values to hi-res *)
WITH PictureImageDetails DO
StartX := boxx;
StartY := boxy * 2;
Width := boxw;
Height := boxh * 2;
END; (* with *)
vs_clip( VDIHandle, FALSE, cliprect );
WaitNoMouseButton;
END DoMedResSelectImage;
PROCEDURE DoHiResSelectImage ( VAR PictureImageDetails : PictureImage;
VAR Picture : HiResScreen );
CONST CRButton = 2;
CLButton = 1;
VAR mox, moy, mbutton, bkstate : CARDINAL;
boxx, boxy, boxw, boxh, mstate : CARDINAL;
dumi : INTEGER;
cliprect : PxyArrayType;
BEGIN
dumi := vswr_mode( VDIHandle, CVDIXorWriteMode );
dumi := vsl_type( VDIHandle, CLineType );
vsl_udsty( VDIHandle, CARDINAL(0AAAAH) );
dumi := vsl_color( VDIHandle, 0 );
cliprect[0] := 0;
cliprect[1] := 0;
cliprect[2] := HiResMaxX;
cliprect[3] := HiResMaxY;
vs_clip( VDIHandle, TRUE, cliprect );
HideMouse;
DisplayFullPicture( Picture );
ShowMouse;
WaitNoMouseButton;
boxx := ( HiResMaxX DIV 2 ) - ( CStartWidth DIV 2 );
boxy := ( HiResMaxY DIV 2 ) - ( CStartHeight DIV 2 );
boxw := CStartWidth;
boxh := CStartHeight;
LOOP (* leave on right button OR Left button outside box *)
DrawXorBox( boxx, boxy, boxw, boxh );
WaitMouseButton( mox, moy, mbutton, bkstate );
DrawXorBox( boxx, boxy, boxw, boxh );
IF ( mbutton = CRButton ) THEN
WaitNoMouseButton;
RETURN
END; (* quit *)
(* outside box? ... accept rectangle if true *)
IF QueryOutsideBox( mox, moy, boxx, boxy, boxw, boxh ) THEN
EXIT
END; (* if *)
IF QueryStretchBox( mox, moy, boxx, boxy, boxw, boxh ) THEN
dumi := Graphics.graf_mouse(PointHand, NIL);
dumi := Graphics.graf_rubberbox( boxx, boxy, CMinWidth, CMinHeight,
boxw, boxh );
dumi := Graphics.graf_mouse(Arrow, NIL);
ELSE
dumi := Graphics.graf_mouse(FlatHand, NIL);
dumi := Graphics.graf_dragbox( boxw, boxh, boxx, boxy,
0, 0,
HiResMaxX+1, HiResMaxY+1,
boxx, boxy );
dumi := Graphics.graf_mouse(Arrow, NIL);
END;
END; (* loop *)
WITH PictureImageDetails DO
StartX := boxx;
StartY := boxy;
Width := boxw;
Height := boxh;
END; (* with *)
vs_clip( VDIHandle, FALSE, cliprect );
WaitNoMouseButton;
END DoHiResSelectImage;
END DCSelImg.